
$(function() {
	var protectActChart;
	getProtectActTime(sid);
	var t1 = window.setInterval(function() {
		var w = $('#protectActDiv').width() + "";
		if (w != '0') {
			var width = parseInt(w) - 10 + 'px';
			$("#protectAct").css("width", width);
			window.clearInterval(t1);
		}
	}, 20);
	$("#protectAlarmDiv").click(function(){
		var width=$('#protectAlarmDiv').css('width');
		$("#alarmInfo").css('width',width);
		$("#alarmLevel").css('width',width);
	});
	// 保护通道频繁中断protectOftenBreak
	var times =0;
	// 挂载点击事件
	$("#alarmDiv").click(function(){
		if(times == 0){init1()}
	})
	$("#protectOftenBreak").click(function() {
		init1();
	});
	//双通道同时中断twoSameTimeBreak
	//挂载点击事件
	$("#twoSameTimeBreak").click(function(){
		init2();
	});
});

// 获取本站所有保护动作时间
//线路保护动作时间
var xl_act_time = [];
var actTimeChartData = {};
//保护名称
var protectName=[];
function getProtectActTime(sid) {
	$.getJSON("/rest/riskwarning/getProtectActTimesByStationId/" + sid,function(result) {
		var noData = true;
		//判断数据是否为空
		if(result.length !=0 && $.isEmptyObject(result) == false){
			var proName = [];
			//做数据筛选，如果一条数据中“protectionName”,“distance0MomentsTime”,"faultTime"任意一个为空，则不展示这条数据
			for(var i=0;i<result.length;i++){
				var xdate = result[i]["faultTime"];
				var ytime = result[i]["distance0MomentsTime"]/1000;
				var name = result[i]["protectionName"];
				if(xdate !="null" && ytime !="null" && name !="null"){
					xl_act_time.push({"faultTime":xdate,"distance0MomentsTime":ytime,"protectionName":name})
					proName.push(name);
				}
			}
			if(xl_act_time.length>0){
				//去重
				proName = uniq(proName);
				//做数据转换，转换成图表可用的格式
				for(var i =0;i<proName.length;i++){
					var name = proName[i];
					actTimeChartData[name]=[];
					for(var j=0;j<xl_act_time.length;j++){
						var data = xl_act_time[j];
						if(name == data["protectionName"]){
							actTimeChartData[name].push([data["faultTime"],data["distance0MomentsTime"]])
						}
					}
				}
				//展示数据
				noData = false;
				
			}
		}
		if(!noData){
			$("#noData").next().show();
			$("#noData").hide();
			initActChart();
		}
		else{
			$("#noData").next().hide();
			$("#noData").show();
		}		
	});
}
//各保护的动作时间折线图
function initActChart() {
	protectActChart = new CategoryLine("protectAct");
	protectActChart.setZoomTool(false).setMagicType(false).setRestore(false);
	var i = 0;
	for ( var name in actTimeChartData) {
		var dateTime = actTimeChartData[name];
		protectActChart.setyAxis(dateTime);
		protectActChart.setyAxisName(name);
		if(i ==0){
			protectActChart.getOption().series[i].label.normal.show = false;
		}else{
			protectActChart.getOption().series[i].label.normal.show = false;
		}
		i++;
	};	
	var opt = protectActChart.getOption();
	opt.toolbox.feature.dataView.optionToContent = function(opt) {
		var series = opt.series;
		var table = '<table border="1" style="width:99%;text-align:center;margin-top:10px"><tbody><tr>';
		for (var j = 0; j < series.length; j++) {
			table = table + '<td colspan=2>' + series[j].name+ '</td></tr><tr>';
			for (var i = 0, l = series[j].data.length; i < l; i++) {
				table += '<td>' + series[j].data[i][0] + '</td><td>'+ series[j].data[i][1] + '</td></tr>';
			}
		}
		table += '</tbody></table>';
		return table;
	};
	var xAxis = protectActChart.getxAxis();
	xAxis.type = 'time';
	opt.legend.orient='vertical';
	opt.legend.align='left';
	opt.legend.left=1;
	opt.legend.width=300;
	opt.grid.left=300;
	protectActChart.setxAxisTitle('日期').setyAxisTitle("动作时间/ms").show();
}
//数组去重
function uniq(array){
    array.sort();
    var temp=[array[0]];
    for(var i = 1; i < array.length; i++){
        if( array[i] !== temp[temp.length-1]){
            temp.push(array[i]);
        }
    }
    return temp;
}     
//保护通道中断公共方法
function onSelectDivClick(pid, cid) {
	var div = $('#' + pid);
	var cbtnIcon = $('#' + cid);
	if (div.hasClass('in')) {
		div.collapse('hide');
		cbtnIcon.removeClass("fa-caret-up").addClass("fa-caret-down");
	} else {
		div.collapse('show');
		cbtnIcon.removeClass("fa-caret-down").addClass("fa-caret-up");
	}
}
function initDate(startId,endId){
	$('#'+startId).val($('#startTime').val()==""?getNowFormatDate("-1"):$('#startTime').val()).datetimepicker({
		format : 'yyyy-mm-dd',
		minView : 2,
		autoclose : true,
		endDate : new Date(),
		todayHighlight : true
	});
	$('#'+endId).val($('#endTime').val()==""?getNowFormatDate("0"):$('#endTime').val()).datetimepicker({
		format : 'yyyy-mm-dd',
		minView : 2,
		autoclose : true,
		endDate : new Date(),
		pickerPosition : 'bottom-left',
		todayHighlight : true
	});
}
function redrawTable() {
	if (table) {
		table.getTable().draw();
	}
}
function str(v) {
	return v ? v : '';
}
function time(v) {
	return DateUtil.locale(v) + ':' + DateUtil.pattern(v, 'ss');
}

function resizeHtml() {
	if (table) {
		table.getTable().draw();
	}
}
function refreshAllSelectAllButtonStatus(sign) {
	var ids = [ 'columns', 'lines', 'voltages' ];
	var signs = sign?sign:'';
	for ( var i in ids) {
		var eles = document.getElementsByName(ids[i] + signs);
		var all = document.getElementById(ids[i] + 'All' + signs);
		var checked = true;
		for (var i = 0; i < eles.length; i++) {
			var show = eles[i].checked;
			if (!show) {
				checked = false;
				break;
			}
		}
		all.checked = checked;
	}
}
function doFilter(sign) {
	var signs = sign?"POB":"";
	var lines = getCheckBoxValue('lines'+signs);
	var voltages = getCheckBoxValue('voltages'+signs);
	if(sign){
		changeSelectButtonStatusPOB(lines, voltages);
	}else{
		changeSelectButtonStatus(lines, voltages);
	}
	currentAlarms = [];
	for ( var i in alarms) {
		var a = alarms[i];
		var line = a.lineName ? a.lineName : undefinedReplace;
		var voltage = a.voltage ? a.voltage : undefinedReplace;
		if (lines.indexOf(line)> -1 &&  voltages.indexOf(voltage)> -1) {
			currentAlarms.push(a);
		}
	}
	if(sign){
		loadContentPOB(currentAlarms);
	}else{
		loadContent(currentAlarms);
	}
	
}
function doColumnFilter(sign) {
	var signs = sign?"POB":'';
	var eles = document.getElementsByName("columns"+signs);
	var length = 0;
	for (var i = 0; i < eles.length; i++) {
		var show = eles[i].checked;
		var col = table.getTable().column(i);
		col.visible(show);
		if (show) {
			length++;
		}
	}
	changeColumnsSelectButtonStatusPOB(length);
	redrawTable();
}
function minusTime(t1, t2) {
	var d1 = new Date(t1.time ? t1.time : t1);
	var d2 = new Date(t2.time ? t2.time : t2);
	return ((d1.getTime() - d2.getTime()) / 60000).toFixed(2);
}
function getCheckBox(data, name, func, map, selects) {
	var c = '';
	for ( var i in data) {
		if (map) {
			var item = map[data[i]];
			var count = item.count;
			var checked = '';
			if (selects.indexOf(data[i]) > -1) {
				checked = ' checked = "checked" ';
			}
			c += '<label title="频繁告警' + count + '次"><input name="' + name
					+ '" type="checkbox" onchange="' + func + '" ' + checked
					+ ' value="' + data[i] + '" />' + data[i] + '</label>';
		} else {
			var checked = '';
			if (selects.indexOf(data[i]) > -1) {
				checked = ' checked = "checked" ';
			}
			c += '<label><input name="' + name + '" type="checkbox" onchange="'
					+ func + '" ' + checked + ' value="' + data[i] + '" />'
					+ data[i] + '</label>';
		}

	}
	return c;
}
function getCheckBoxValue(name) {
	var obj = document.getElementsByName(name);
	var s = [];
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked) {
			s.push(obj[i].value);
		}
	}
	return s;
}
  
function loadFilter(sign) {
	var lines = [];
	var lineMap = {};
	for ( var i in alarms) {
		var a = alarms[i];
		var line = a.lineName ? a.lineName : undefinedReplace;
		if (lines.indexOf(line) == -1) {lines.push(line);}
		// 加title
		var l = lineMap[line];
		if (!l) {l = {count : 0};lineMap[line] = l;}
		l.count++;
	}
	// 先按照count排，count相同按照总时长
	lines.sort(sortLinesPOB);
	linesLength = lines.length;
	if(sign){
		$('#linesPOB').html(getCheckBox(lines, 'linesPOB', 'doFilter(1);',lineMap, lines));
	}else{
		$('#lines').html(getCheckBox(lines, 'lines', 'doFilter();', lineMap, lines));
	}
	selectAllVoltagesPOB(sign);
	function sortLinesPOB(line1, line2) {
		var t1 = line1 == undefinedReplace ? 0 : 1;
		var t2 = line2 == undefinedReplace ? 0 : 1;
		if (t2 + t1 < 2) {
			return t2 - t1;
		}
		var m1 = lineMap[line1];
		var m2 = lineMap[line2];
		return m2.count - m1.count;
	}
	function selectAllVoltagesPOB(sign) {
		var signs = sign?sign:""; 
		var ss = document.getElementsByName("voltages"+signs);
		var ssAll = document.getElementById("voltagesAll"+signs);
		ssAll.checked = true;
		for ( var i in ss) {
			ss[i].checked = true;
		}
	}
}
// 保护通道频繁中断protectOftenBreak

/**
 * 提供一个获取当前策略参数的接口
 */
var StrategyComponent = (function() {
	// 得到默认值
	var defaultParam1 = 30;
	var defaultParam2 = 5;
	$.ajax({
		url : '/rest/protectAlarm/getFrequentProtectInterruptAlarmParams',
		type : 'get',
		dataType : 'json',
		async : false,
		success : function(data) {
			defaultParam1 = data[0];
			defaultParam2 = data[1];
		}
	});
	var lastP1 = defaultParam1;
	var lastP2 = defaultParam2;

	var outputDiv = $('#strategyOutputPOB');
	var edit = $('#strategyEditPOB');
	var outputParam1 = $('#strategyParam12POB').html(lastP1);
	var outputParam2 = $('#strategyParam22POB').html(lastP2);

	var inputDiv = $('#strategyInputPOB');
	var check = $('#strategyCheckPOB');
	var close = $('#strategyClosePOB');
	var inputParam1 = $('#strategyParam11POB');
	var inputParam2 = $('#strategyParam21POB');
	edit.click(function() {
		outputDiv.hide();
		inputParam1.val(lastP1);
		inputParam2.val(lastP2);
		inputDiv.show();
	});
	check.click(function() {
		lastP1 = inputParam1.val();
		if (!lastP1 || Number(lastP1) < 1) {
			lastP1 = defaultParam1;
		}

		lastP2 = inputParam2.val();
		if (!lastP2 || Number(lastP2) < 1) {
			lastP2 = defaultParam1;
		}
		outputParam1.html(lastP1);
		outputParam2.html(lastP2);

		inputDiv.hide();
		outputDiv.show();
	});
	close.click(function() {
		outputParam1.html(lastP1);
		outputParam2.html(lastP2);

		inputDiv.hide();
		outputDiv.show();
	});
	return {
		getParams : function() {
			return [ lastP1, lastP2 ];
		}
	};
})();


function init1() {
	linesLength = 0;
	start = $('#startTime').val()==""?getNowFormatDate("-1"):$('#startTime').val();
	end = $('#endTime').val()==""?getNowFormatDate("0"):$('#endTime').val();	
	columns = [locale.XuHao, locale.ShouCiGaoJing, locale.DianYa, locale.XianLu, locale.BaoHu, locale.ZongJi,locale.mingXi];
	alarms = [];
	currentAlarms = [];
	table = null;
	initColumns = columns;
	linesLength = 0;
	voltagesLength = 2;
	//清空表格内容
	$("#tableDivPOB").html('<table id="alarmTablePOB" class="table table-gray"></table>');
	initDate('startPOB','endPOB');
	loadColumnsFilterPOB(initColumns);
	$.ajaxSettings.async = false;
	loadDataPOB();
	$.ajaxSettings.async = true;
	$('#alarmTablePOB tbody').on('click','td.details-control',function() {
		var tr = $(this).closest('tr');
		var row = table.getTable().row(tr);
		if (row.child.isShown()) {// This row is already open
			// - close it
			row.child.hide();
			tr.removeClass('shown');
		} else {// Open this row
			var rowIndex = row.data()[0] - 1;
			var detailTableId = 'rowDetail' + rowIndex+ 'TablePOB';
			row.child(format(detailTableId)).show();
			loadDetailTablePOB(detailTableId, rowIndex);
			tr.addClass('shown');
		}
		function format(id) {
			return '<table id="'+ id+'"  class="table table-bordered table-blue"></table>';
		}
	});
}
function loadColumnsFilterPOB(selectColumns) {
	if (!selectColumns) {
		selectColumns = columns;
	}
	$('#columnsPOB').html(getCheckBox(columns, 'columnsPOB', 'doColumnFilter(1)', null,selectColumns));
}

function loadDataPOB() {
	var params = StrategyComponent.getParams();
	var loading = layer.load(2, {
		shade : [ 0.1, 'black' ]
	});
	$.getJSON("/rest/protectAlarm/getFrequentProtectInterruptAlarmByStationId/"+ start + "/" + end + "/" + params[0] + "/" + params[1]+ "/" + sid, function(result) {
		alarms = result;
		loadFilter('POB');
		currentAlarms = [];
		if (sid) {
			for ( var i in alarms) {
				//if (alarms[i].sid == sid) {currentAlarms.push(alarms[i]);}
				currentAlarms.push(alarms[i]);
			}
			loadContentPOB(currentAlarms);
		} 
		else {currentAlarms = alarms;loadContentPOB(alarms);}
		layer.close(loading);
	});
}



function queryPOB() {
	start = $('#startPOB').val();
	end = $('#endPOB').val();
	loadDataPOB();
}
function changeSelectButtonStatusPOB(lines, voltages) {
	if (lines.length == linesLength && voltages.length == voltagesLength) {
		$('#selectButtonPOB').removeClass('hasSelected');
	} else {
		$('#selectButtonPOB').addClass('hasSelected');
	}
}
function changeColumnsSelectButtonStatusPOB(length) {
	var csBtn = $('#columnsSelectButtonPOB');
	columns.length == length ? csBtn.removeClass('hasSelected') : csBtn
			.addClass('hasSelected');
}
function loadContentPOB(alarms) {
	loadTablePOB(alarms);
	refreshAllSelectAllButtonStatus('POB');
}
function loadTablePOB(alarms) {
	if (table) {table.getTable().destroy();}	
	var opt = MyTable.getDefaultOptions();
	opt.paging = false;
	opt.autoWidth = false;
	opt.serverSide = false;
	var defs = [ {targets : 0,width : '3%'}, {targets : 1,width : '15%'}, 
	{targets : 2,width : '5%'}, {targets : 3,width : '7%'},
	{targets : 4,width : '20%'}, {targets : 5,width : '10%'}, 
	{targets : 6,width : '5%',className : "details-control"} ];
	opt.scrollY = scrollYHeight;
	opt.scrollX = false;
	var datas = [];
	var totalMils=0;//总时间毫秒数
	var totalTimes=0;//总次数
	for ( var i in alarms) {
		var f = alarms[i];
		var as = f.alarms;
		totalMils+=f.continueMs;
		var startTime = time(as[0].eventStart) + '.' + str(as[0].mStartMs);
		var t = (f.continueMs / 60000).toFixed(2);
		var count = '<span style="color:red;margin:3px;">' + t + '</span>分钟';
		datas.push([ Number(i) + 1, startTime, str(f.voltage), str(f.lineName),
				str(f.protectName), count, '' ]);
		for(var j in as){
			if(as[j].channelAlarms && as[j].channelAlarms.length > 0){
				totalTimes++;
				break;
			}
		}
	}
	// 筛选列
	var eles = document.getElementsByName('columnsPOB');
	var targets = [];
	for (var i = 0; i < eles.length; i++) {
		if (!eles[i].checked) {targets.push(i);}
	}
	defs.push({
		visible : false,
		targets : targets
	});
	opt.columnDefs = defs;
	table = new MyTable("alarmTablePOB", columns, opt);
	table.setDataSet(datas).show();
	$("#totalNum1POB").html(alarms.length);
	$("#totalMinutes1POB").html(totalMils > 0 ? (totalMils / 60000).toFixed(2) : totalMils);
	$("#totalTimes1POB").html(totalTimes);
	$("#totalNum2POB").html(alarms.length);
	$("#totalMinutes2POB").html(totalMils > 0 ? (totalMils / 60000).toFixed(2) : totalMils);
	$("#totalTimes2POB").html(totalTimes);
}

function loadDetailTablePOB(tableId, rowIndex) {
	var as = currentAlarms[rowIndex].alarms;
	var columns = [ locale.XuHao, locale.GaoJingShiJian, locale.BianDianZhan,
			locale.BaoHu, locale.GaoJingNeiRong, locale.ZhongDuanShiChang,
			locale.YiChangDingWei ];
	var dataset = [];
	var opt = MyTable.getDefaultOptions();
	opt.paging = false;
	opt.autoWidth = false;
	var defs = [ {targets : 0,width : '5%'}, {targets : 1,width : '15%'},
		{targets : 2,width : '10%'}, {targets : 3,width : '10%'},
		{targets : 4,width : '15%'}, {targets : 5,width : '10%'},
		{targets : 6,width : '30%'} ];
	opt.scrollY = "300px";
	opt.scrollX = false;
	opt.scrollCollapse = true;
	for (var i = 0; i < as.length; i++) {
		var f = as[i];
		var channels = "<span style='color:gray;'>无通道告警信息</span>";
		if (f.channelAlarms && f.channelAlarms.length > 0) {
			channels = "<ul>";
			for ( var j in f.channelAlarms) {
				var a = f.channelAlarms[j];
				channels += "<li>" + a.alarmChannel + "</br>" + a.alarmObject
						+ "</br><span style='color:red;'>" + a.name+ "</span></li>";
			}
			channels += "</ul>";
		}
		var durationTime = f.durationTime;
		var title = '';
		if (durationTime) {
			title = 'title="' + (durationTime / 60000).toFixed(2) + '分钟"';
			durationTime = durationTime + 'ms';
		} else {
			durationTime = '未复归';
		}
		durationTime = '<span ' + title + ' style="color:red;">' + durationTime+ '</span>';
		dataset.push([ Number(i) + 1, time(f.eventStart) + '.' + f.mStartMs,
				str(f.stationName), str(f.protectType), str(f.alarmMsg),
				durationTime, channels ]);
	}
	opt.columnDefs = defs;
	var table = new MyTable(tableId, columns, opt);
	table.setDataSet(dataset).show();
}
function selectAllPOB(isChecked, name) {
	var eles = document.getElementsByName(name);
	for (var i = 0; i < eles.length; i++) {
		eles[i].checked = isChecked;
	}
	doFilter('POB');
}

function selectAllColumnsPOB(isChecked, name) {
	var eles = document.getElementsByName(name);
	for (var i = 0; i < eles.length; i++) {
		eles[i].checked = isChecked;
	}
	doColumnFilter('POB');
}

//双通道同时中断twoSameTimeBreak

//初始化
function init2() {
	linesLength = 0;
	start = $('#startTime').val()==""?getNowFormatDate("-1"):$('#startTime').val();
	end = $('#endTime').val()==""?getNowFormatDate("0"):$('#endTime').val();	
	columns = [ locale.XuHao, locale.ShouCiGaoJing, locale.DianYa, locale.XianLu, locale.BaoHu, locale.ZongJi,locale.mingXi ];
	alarms = [];
	currentAlarms = [];
	table = null;
	initColumns = columns;
	linesLength = 0;
	voltagesLength = 2;
	linesLength = 0;
	//清空表格内容
	$("#tableDiv").html('<table id="alarmTable" class="table table-gray"></table>');
	initDate('start','end');
	loadColumnsFilter(initColumns);
	$.ajaxSettings.async = false;
	loadData();
	$.ajaxSettings.async = true;
	$('#alarmTable tbody').on('click','td.details-control',function() {
		var tr = $(this).closest('tr');
		var row = table.getTable().row(tr);
		if (row.child.isShown()) {// This row is already open - close it
			row.child.hide();
			tr.removeClass('shown');
		} else {// Open this row
			var rowIndex = row.data()[0] - 1;
			var detailTableId = 'rowDetail' + rowIndex+ 'Table';
			row.child(format(detailTableId)).show();
			loadDetailTable(detailTableId, rowIndex);
			tr.addClass('shown');
		}
		function format(id) {return '<table id="'+ id+ '"  class="table table-bordered table-blue"></table>';}
	});
}
function loadColumnsFilter(selectColumns) {
	if (!selectColumns) {
		selectColumns = columns;
	}
	$('#columns').html(getCheckBox(columns, 'columns', 'doColumnFilter();', null, selectColumns));
}
function loadData() {
	var loading = layer.load(2,{shade:[0.1,'black']});
	$.getJSON("/rest/protectAlarm/getFrequentDoubleChannelAlarmByStationId/" + start + "/"+ end+"/"+sid, function(result) {
		alarms = result;
		loadFilter();
		currentAlarms = [];
		if (sid) {
			for ( var i in alarms) {
				currentAlarms.push(alarms[i]);
			}
			loadContent(currentAlarms);
		} else {
			currentAlarms = alarms;
			loadContent(alarms);
		}
		//sid = undefined;
		layer.close(loading);
	});
}

function query() {
	var s = $('#start').val();
	var e = $('#end').val();
	if (s == start && e == end) {doFilter();}
	else {start = s;end = e;loadData();}
}
function changeSelectButtonStatus(lines, voltages) {
	if (lines.length == linesLength && voltages.length == voltagesLength) {
		$('#selectButton').removeClass('hasSelected');
	} else {
		$('#selectButton').addClass('hasSelected');
	}
}
function changeColumnsSelectButtonStatus(length) {
	if (columns.length == length) {
		$('#columnsSelectButton').removeClass('hasSelected');
	} else {
		$('#columnsSelectButton').addClass('hasSelected');
	}
}

function loadContent(alarms) {
	loadTable(alarms);
	refreshAllSelectAllButtonStatus();
}
function loadTable(alarms) {
	if (table) {table.getTable().destroy();}	
	var opt = MyTable.getDefaultOptions();
	opt.paging = false;
	opt.autoWidth = false;
	var defs = [ {targets : 0,width : '3%'}, {targets : 1,width : '15%'}, 
	{targets : 2,width : '5%'}, {targets : 3,width : '7%'},
	{targets : 4,width : '20%'}, {targets : 5,width : '10%'}, 
	{targets : 6,width : '5%',className : "details-control"} ];
	opt.scrollY = true;
	opt.scrollX = false;
	var datas = [];
	var totalMils=0;//总时间毫秒数
	var totalTimes=0;//总次数
	for ( var i in alarms) {
		var f = alarms[i];
		var as = f.alarms;
		totalMils+=f.continueMs;
		var startTime = time(as[0].eventStart) + '.' + str(as[0].mStartMs);
		var t = (f.continueMs / 60000).toFixed(2);
		var count = '<span style="color:red;margin:3px;">' + t + '</span>分钟';
		datas.push([ Number(i) + 1, startTime, str(f.voltage), str(f.lineName),
				str(f.protectName), count, '' ]);
		for(var j in as){
			if(as[j].channelAlarms && as[j].channelAlarms.length > 0){
				totalTimes++;
				break;
			}
		}
	}
	// 筛选列
	var eles = document.getElementsByName('columns');
	var targets = [];
	for (var i = 0; i < eles.length; i++) {
		if (!eles[i].checked) {targets.push(i);}
	}
	defs.push({
		visible : false,
		targets : targets
	});
	opt.columnDefs = defs;
	table = new MyTable("alarmTable", columns, opt);
	table.setDataSet(datas).show();
	$("#totalNum").html(alarms.length);
	$("#totalMinutes").html(totalMils>0?(totalMils / 60000).toFixed(2):totalMils);
	$("#totalTimes").html(totalTimes);
}
function loadDetailTable(tableId, rowIndex) {
	var as = currentAlarms[rowIndex].alarms;
	var columns = [ locale.XuHao, locale.GaoJingShiJian, locale.BianDianZhan, 
		locale.BaoHu, locale.GaoJingNeiRong, locale.ZhongDuanShiChang,
		locale.YiChangDingWei];
	var dataset = [];
	var opt = MyTable.getDefaultOptions();
	opt.paging = false;
	opt.autoWidth = false;
	var defs = [ {targets : 0,width : '5%'}, {targets : 1,width : '10%'},
		{targets : 2,width : '7%'}, {targets : 3,width : '22%'},
		{targets : 4,width : '15%'}, {targets : 5,width : '13%'},
		{targets : 6,width : '20%'} ];
	opt.scrollY = "300px";
	opt.scrollX = false;
	opt.scrollCollapse = true;
	for (var i = 0; i < as.length; i++) {
		var f = as[i];
		var channels = "<span style='color:gray;'>无通道告警信息</span>";
		if (f.channelAlarms && f.channelAlarms.length > 0) {
			channels = "<ul>";
			for ( var j in f.channelAlarms) {
				var a = f.channelAlarms[j];
				channels += "<li>" + a.alarmChannel + "</br>" + a.alarmObject
						+ "</br><span style='color:red;'>" + a.name+ "</span></li>";
			}
			channels += "</ul>";
		}
		var durationTime = f.durationTime;
		var title = '';
		if (durationTime) {
			title = 'title="' + (durationTime / 60000).toFixed(2) + '分钟"';
			durationTime = durationTime + 'ms';
		} else {durationTime = '未复归';}
		durationTime = '<span ' + title + ' style="color:red;">' + durationTime+ '</span>';
		dataset.push([ Number(i) + 1, time(f.eventStart) + '.' + f.mStartMs,
				str(f.stationName), str(f.protectName), str(f.alarmMsg),
				durationTime, channels ]);
	}
	opt.columnDefs = defs;
	var table = new MyTable(tableId, columns, opt);
	table.setDataSet(dataset).show();
}
function selectAll(isChecked, name) {
	var eles = document.getElementsByName(name);
	for (var i = 0; i < eles.length; i++) {
		eles[i].checked = isChecked;
	}
	doFilter();
}

function selectAllColumns(isChecked, name) {
	var eles = document.getElementsByName(name);
	for (var i = 0; i < eles.length; i++) {
		eles[i].checked = isChecked;
	}
	doColumnFilter();
}
//=====获取日期
function getNowFormatDate(type) {
    //获取当天日期
	if(type=="0"){
    	var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
	//获取前一天日期
    else if(type=="-1"){
    	var time=(new Date).getTime()-24*60*60*1000;
    	var yesterday=new Date(time);
    	var month=yesterday.getMonth();
    	yesterday=yesterday.getFullYear() + "-" 
    	          + (yesterday.getMonth()> 9 ? (yesterday.getMonth() + 1) : "0" + (yesterday.getMonth() + 1)) 
    	          + "-" +(yesterday.getDate()> 9 ? (yesterday.getDate()) : "0" + (yesterday.getDate()+1));
    	return yesterday;
    }
}
